package com.mv.webserver.conf;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class Config {
	private int port = 8080;
	public static final String DISPATCHER_SERVLET = "dispatcherServlet";
	
	public Config(){
		System.err.println("tomcat config create");
		init();
	}
	
	

	public void init(){
		Properties properties = new Properties();
	    try {
	    	InputStream stream = this.getClass().getResourceAsStream("config.properties");//tomcat路径 Java工程打包部署到Tomcat中时，properties的路径变到顶层（classes下）
	    	if(stream == null) {
	    		 File file = new File("src/main/resources/config.properties");//程序开发环境路径  
	    		 stream = new FileInputStream(file);
	    	}
			properties.load(stream);//src/main/resources 下

		} catch (IOException e) {
			e.printStackTrace();
		}
	 
	    String value = properties.getProperty("tomcat.port");
	    port = Integer.parseInt(value);
	
	    System.err.println("tomcat config port:" + port);
	}
	
	public int getPort() {
		return port;
	}
}
